package com.lcredu.aop.homework.xml;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author 黎长容
 * @date 2025-07-15 20:09
 */
public class CalAspect {
    //定义切入点
    public void myPointCut() {

    }

    //前置通知
    public void getStartTime() {
        System.out.println("开始计算时间= " + System.currentTimeMillis());
    }

    //返回通知
    public void getResult(JoinPoint joinPoint, Object result) {
        Signature signature = joinPoint.getSignature();
        String simpleName = signature.getDeclaringType().getSimpleName();
        String methodName = signature.getName();
        System.out.println(simpleName + "的方法" + methodName + "的计算结果=" + result);
    }

    //异常通知
    public void getExpectation(JoinPoint joinPoint, Throwable throwable) {
        Signature signature = joinPoint.getSignature();
        String simpleName = signature.getDeclaringType().getSimpleName();
        System.out.println(simpleName + "捕获到异常:" + throwable);
    }

    //最终通知
    public void after(JoinPoint joinPoint) {
        System.out.println("结束计算时间= " + System.currentTimeMillis());
    }
}
